﻿using CBUMachineDataManage.MachineData;
using HslCommunication;
using HslCommunication.Profinet.Omron;
using NDK.Module.Model;
using NDK.Module.Model.Quebec;
using NDK.Motion.Card;
using NDK.Motion.MachineManager;
using NDK.Motion.MachineResources;
//using CSharp_OPTControllerAPI;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
//using motormaster;

namespace NDK.Motion.BLL
{
    public static class Machine
    {

        public static KeyencePPG PPG = new KeyencePPG();
        #region DI
        public static InputSetting di_启动按钮 = null;
        public static InputSetting di_复位按钮 = null;
        public static InputSetting di_停止按钮 = null;
        public static InputSetting di_手自动按钮 = null;
        public static InputSetting di_急停按钮1 = null;
        public static InputSetting di_急停按钮2 = null;
        public static InputSetting di_气压检测 = null;
        public static InputSetting di_安全门1 = null;
        public static InputSetting di_安全门2 = null;
        public static InputSetting di_安全门3 = null;
        public static InputSetting di_安全门4 = null;
        public static InputSetting di_安全门5 = null;
        public static InputSetting di_安全门6 = null;
        public static InputSetting di_转盘光电检测1 = null;
        public static InputSetting di_转盘光电检测2 = null;
        public static InputSetting di_转盘光电检测3 = null;
        public static InputSetting di_转盘光电检测4 = null;
        public static InputSetting di_转盘光电检测5 = null;
        public static InputSetting di_转盘光电检测6 = null;
        public static InputSetting di_转盘光电检测7 = null;
        public static InputSetting di_转盘光电检测8 = null;
        public static InputSetting di_转盘真空检测1 = null;
        public static InputSetting di_转盘真空检测2 = null;
        public static InputSetting di_转盘真空检测3 = null;
        public static InputSetting di_转盘真空检测4 = null;
        public static InputSetting di_转盘真空检测5 = null;
        public static InputSetting di_转盘真空检测6 = null;
        public static InputSetting di_转盘真空检测7 = null;
        public static InputSetting di_转盘真空检测8 = null;
        public static InputSetting di_转盘下料真空检测1 = null;
        public static InputSetting di_转盘下料真空检测2 = null;
        public static InputSetting di_翻转真空检测1 = null;
        public static InputSetting di_翻转真空检测2 = null;
        public static InputSetting di_下料搬运真空检测1 = null;
        public static InputSetting di_下料搬运真空检测2 = null;
        #endregion

        #region DO 
        public static OutputSetting do_启动按钮灯 = null;
        public static OutputSetting do_复位按钮灯 = null;
        public static OutputSetting do_停止按钮灯 = null;
        public static OutputSetting do_红灯 = null;
        public static OutputSetting do_黄灯 = null;
        public static OutputSetting do_绿灯 = null;
        public static OutputSetting do_蜂鸣器 = null;
        public static OutputSetting do_日光灯 = null;
        public static OutputSetting do_测高通断阀输出 = null;
        public static OutputSetting do_扫码枪触发 = null;
        public static OutputSetting do_安全门1 = null;
        public static OutputSetting do_安全门2 = null;
        public static OutputSetting do_安全门3 = null;
        public static OutputSetting do_安全门4 = null;
        public static OutputSetting do_安全门5 = null;
        public static OutputSetting do_安全门6 = null;
        public static OutputSetting do_上料CCD触发 = null;
        public static OutputSetting do_上CCD触发 = null;
        public static OutputSetting do_外CCD触发 = null;
        public static OutputSetting do_内CCD触发 = null;
        public static OutputSetting do_上激光触发 = null;
        public static OutputSetting do_侧激光触发 = null;
        public static OutputSetting do_侧激光触发1 = null;
        public static OutputSetting do_侧激光触发2 = null;
        public static OutputSetting do_侧激光触发3 = null;
        public static OutputSetting do_侧激光触发4 = null;
        public static OutputSetting do_下激光触发 = null;
        public static OutputSetting do_转盘真空吸1 = null;
        public static OutputSetting do_转盘真空破1 = null;
        public static OutputSetting do_转盘真空吸2 = null;
        public static OutputSetting do_转盘真空破2 = null;
        public static OutputSetting do_转盘真空吸3 = null;
        public static OutputSetting do_转盘真空破3 = null;
        public static OutputSetting do_转盘真空吸4 = null;
        public static OutputSetting do_转盘真空破4 = null;
        public static OutputSetting do_转盘真空吸5 = null;
        public static OutputSetting do_转盘真空破5 = null;
        public static OutputSetting do_转盘真空吸6 = null;
        public static OutputSetting do_转盘真空破6 = null;
        public static OutputSetting do_转盘真空吸7 = null;
        public static OutputSetting do_转盘真空破7 = null;
        public static OutputSetting do_转盘真空吸8 = null;
        public static OutputSetting do_转盘真空破8 = null;
        public static OutputSetting do_转盘下料真空吸1 = null;
        public static OutputSetting do_转盘下料真空破1 = null;
        public static OutputSetting do_转盘下料真空吸2 = null;
        public static OutputSetting do_转盘下料真空破2 = null;
        public static OutputSetting do_翻转真空吸1 = null;
        public static OutputSetting do_翻转真空破1 = null;
        public static OutputSetting do_翻转真空吸2 = null;
        public static OutputSetting do_翻转真空破2 = null;
        public static OutputSetting do_下料搬运真空吸1 = null;
        public static OutputSetting do_下料搬运真空破1 = null;
        public static OutputSetting do_下料搬运真空吸2 = null;
        public static OutputSetting do_下料搬运真空破2 = null;
        #endregion

        #region 点位
        public static Position pos_激光扫描起始位_转盘工位三 = null;
        public static Position pos_激光扫描终点位_转盘工位三 = null;
        public static Position pos_激光扫描起始位_转盘工位五 = null;
        public static Position pos_激光扫描终点位_转盘工位五 = null;
        public static Position pos_激光扫描起始位_转盘工位六 = null;
        public static Position pos_激光扫描终点位_转盘工位六 = null;
        public static Position pos_激光扫描安全位_转盘工位六 = null;
        public static Position pos_激光扫描起始位_转盘工位七 = null;
        public static Position pos_激光扫描终点位_转盘工位七 = null;
        public static Position pos_取料位_转盘下料工位 = null;
        public static Position pos_取料高位_转盘下料工位 = null;
        public static Position pos_放料位_转盘下料工位 = null;
        public static Position pos_放料高位_转盘下料工位 = null;
        public static Position pos_激光扫描起始位_下激光工位 = null;
        public static Position pos_激光扫描终点位_下激光工位 = null;
        public static Position pos_接料位1_扫码工位 = null;
        public static Position pos_接料位2_扫码工位 = null;
        public static Position pos_扫码位1_扫码工位 = null;
        public static Position pos_扫码位2_扫码工位 = null;
        public static Position pos_取料位_扫码工位 = null;
        public static Position pos_取料位_下料翻转工位 = null;
        public static Position pos_真空确认位_下料翻转工位 = null;
        public static Position pos_取料接近位_下料翻转工位 = null;
        public static Position pos_放料位_下料翻转工位 = null;
        public static Position pos_取料位_下料搬运工位 = null;
        public static Position pos_放料位_下料搬运工位 = null;
        public static Position pos_取料高位_下料搬运工位 = null;
        public static Position pos_放料高位_下料搬运工位 = null;
        public static Position pos_安全位_下料搬运工位 = null;
        public static Position pos_转盘初始位_转盘旋转 = null;
        public static Position pos_接料位_PPG搬运工位 = null;
        public static Position pos_PPG下方位_PPG搬运工位 = null;
        public static Position pos_取料位_PPG搬运工位 = null;
        public static Position pos_安全位_PPG下压工位 = null;
        public static Position pos_过渡位_PPG下压工位 = null;
        public static Position pos_下压位_PPG下压工位 = null;
        #endregion

        public static OutputSetting[] VacuunArray_转盘真空吸;
        public static OutputSetting[] VacuunArray_转盘真空破;
        public static InputSetting[] VacuunArray_转盘真空检测;

        public static Position[] PosArray_扫码工位接料;
        public static Position[] PosArray_扫码工位扫码;

        public static OutputSetting[] VacuumArray_翻转真空吸;
        public static OutputSetting[] VacuumArray_翻转真空破;

        #region 光源
        public static ImageLights imageLights_上料定位光源;
        public static ImageLights imageLights_四工站蓝光光源;
        public static ImageLights imageLights_四工站蓝光光源2;
        public static ImageLights imageLights_四工站蓝光光源3;
        public static ImageLights imageLights_三工站蓝光光源;
        public static ImageLights imageLights_三工站蓝光光源2;
        public static ImageLights imageLights_三工站蓝光光源3;

        public static ImageLights[] imageAllLight = new ImageLights[8];
        #endregion

        public static bool ImageLightInit(string ProjectName)
        {
            if (ProjectName != "Product")
                ProjectName = "Block";
            if (MachineDataManager.Instance.ProjectImageLights.Count == 0)
                return false;
            var findItem = MachineDataManager.Instance.ProjectImageLights.Find(x => x.Name.Equals(ProjectName));
            List<ImageLights> CurProjectImageLightslist;
            if (findItem != null)
                CurProjectImageLightslist = findItem.ImageLightsList;
            else
                return false;


            imageLights_三工站蓝光光源 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "三工站拍照1光源");
            imageLights_三工站蓝光光源2 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "三工站拍照2光源");
            imageLights_三工站蓝光光源3 = CurProjectImageLightslist.SingleOrDefault(i=> i.ImageName == "三工站拍照3光源");
            imageLights_四工站蓝光光源 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "四工站拍照1光源");
            imageLights_四工站蓝光光源2 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "四工站拍照2光源");
            imageLights_四工站蓝光光源3 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "四工站拍照3光源");
            imageLights_上料定位光源 = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "上料定位光源");

            imageAllLight[0] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位1背光");
            imageAllLight[1] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位2背光");
            imageAllLight[2] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位3背光");
            imageAllLight[3] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位4背光");
            imageAllLight[4] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位5背光");
            imageAllLight[5] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位6背光");
            imageAllLight[6] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位7背光");
            imageAllLight[7] = CurProjectImageLightslist.SingleOrDefault(i => i.ImageName == "转盘工位8背光");


            Common.AppendUiLog.Log($"当前光源Source为{ProjectName}", BZ.Logger.LogType.Alert);
            return true;
        }


        /// <summary>
        /// 资源初始化
        /// </summary>
        /// <returns></returns>

        public static void MachineResourceInit()
        {
            try
            {
                #region DI
                try
                {
                    di_启动按钮 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "启动按钮");
                    di_复位按钮 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "复位按钮");
                    di_停止按钮 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "停止按钮");
                    di_手自动按钮 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "手自动按钮");
                    di_急停按钮1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "急停按钮1");
                    di_急停按钮2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "急停按钮2");
                    di_气压检测 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "气压检测");
                    di_安全门1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门1");
                    di_安全门2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门2");
                    di_安全门3 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门3");
                    di_安全门4 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门4");
                    di_安全门5 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门5");
                    di_安全门6 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "安全门6");
                    di_转盘光电检测1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测1");
                    di_转盘光电检测2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测2");
                    di_转盘光电检测3 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测3");
                    di_转盘光电检测4 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测4");
                    di_转盘光电检测5 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测5");
                    di_转盘光电检测6 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测6");
                    di_转盘光电检测7 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测7");
                    di_转盘光电检测8 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘光电检测8");
                    di_转盘真空检测1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测1");
                    di_转盘真空检测2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测2");
                    di_转盘真空检测3 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测3");
                    di_转盘真空检测4 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测4");
                    di_转盘真空检测5 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测5");
                    di_转盘真空检测6 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测6");
                    di_转盘真空检测7 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测7");
                    di_转盘真空检测8 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘真空检测8");
                    di_转盘下料真空检测1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘下料真空检测1");
                    di_转盘下料真空检测2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "转盘下料真空检测2");
                    di_翻转真空检测1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "翻转真空检测1");
                    di_翻转真空检测2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "翻转真空检测2");
                    di_下料搬运真空检测1 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "下料搬运真空检测1");
                    di_下料搬运真空检测2 = MachineDataManager.Instance.DIList.SingleOrDefault(d => d.Name == "下料搬运真空检测2");
                }
                catch { }
                #endregion

                #region DO
                try
                {
                    do_启动按钮灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "启动按钮灯");
                    do_复位按钮灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "复位按钮灯");
                    do_停止按钮灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "停止按钮灯");
                    do_红灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "红灯");
                    do_黄灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "黄灯");
                    do_绿灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "绿灯");
                    do_蜂鸣器 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "蜂鸣器");
                    do_日光灯 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "日光灯");
                    do_测高通断阀输出 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "测高通断阀输出");
                    do_扫码枪触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "扫码枪触发");
                    do_安全门1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门1");
                    do_安全门2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门2");
                    do_安全门3 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门3");
                    do_安全门4 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门4");
                    do_安全门5 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门5");
                    do_安全门6 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "安全门6");
                    do_上料CCD触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "上料CCD触发");
                    do_上CCD触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "上CCD触发");
                    do_外CCD触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "外CCD触发");
                    do_内CCD触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "内CCD触发");
                    do_上激光触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "上激光触发");
                    do_侧激光触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "侧激光触发");
                    do_侧激光触发1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "侧激光触发1");
                    do_侧激光触发2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "侧激光触发2");
                    do_侧激光触发3 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "侧激光触发3");
                    do_侧激光触发4 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "侧激光触发4");
                    do_下激光触发 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "下激光触发");
                    do_转盘真空吸1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸1");
                    do_转盘真空破1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破1");
                    do_转盘真空吸2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸2");
                    do_转盘真空破2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破2");
                    do_转盘真空吸3 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸3");
                    do_转盘真空破3 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破3");
                    do_转盘真空吸4 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸4");
                    do_转盘真空破4 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破4");
                    do_转盘真空吸5 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸5");
                    do_转盘真空破5 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破5");
                    do_转盘真空吸6 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸6");
                    do_转盘真空破6 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破6");
                    do_转盘真空吸7 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸7");
                    do_转盘真空破7 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破7");
                    do_转盘真空吸8 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空吸8");
                    do_转盘真空破8 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘真空破8");
                    do_转盘下料真空吸1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘下料真空吸1");
                    do_转盘下料真空破1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘下料真空破1");
                    do_转盘下料真空吸2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘下料真空吸2");
                    do_转盘下料真空破2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "转盘下料真空破2");
                    do_翻转真空吸1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "翻转真空吸1");
                    do_翻转真空破1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "翻转真空破1");
                    do_翻转真空吸2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "翻转真空吸2");
                    do_翻转真空破2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "翻转真空破2");
                    do_下料搬运真空吸1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "下料搬运真空吸1");
                    do_下料搬运真空破1 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "下料搬运真空破1");
                    do_下料搬运真空吸2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "下料搬运真空吸2");
                    do_下料搬运真空破2 = MachineDataManager.Instance.DOList.SingleOrDefault(d => d.Name == "下料搬运真空破2");
                }
                catch { }
                #endregion

                #region 点位
                pos_激光扫描起始位_转盘工位三 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描起始位" && d.Station == "转盘工位三");
                pos_激光扫描终点位_转盘工位三 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描终点位" && d.Station == "转盘工位三");
                pos_激光扫描起始位_转盘工位五 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描起始位" && d.Station == "转盘工位五");
                pos_激光扫描终点位_转盘工位五 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描终点位" && d.Station == "转盘工位五");
                pos_激光扫描起始位_转盘工位六 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描起始位" && d.Station == "转盘工位六");
                pos_激光扫描安全位_转盘工位六 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描安全位" && d.Station == "转盘工位六");
                pos_激光扫描终点位_转盘工位六 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描终点位" && d.Station == "转盘工位六");

                pos_激光扫描起始位_转盘工位七 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描起始位" && d.Station == "转盘工位七");
                pos_激光扫描终点位_转盘工位七 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描终点位" && d.Station == "转盘工位七");
                pos_取料位_转盘下料工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料位" && d.Station == "转盘下料工位");
                pos_取料高位_转盘下料工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料高位" && d.Station == "转盘下料工位");
                pos_放料位_转盘下料工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "放料位" && d.Station == "转盘下料工位");
                pos_放料高位_转盘下料工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "放料高位" && d.Station == "转盘下料工位");
                pos_激光扫描起始位_下激光工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描起始位" && d.Station == "下激光工位");
                pos_激光扫描终点位_下激光工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "激光扫描终点位" && d.Station == "下激光工位");
                pos_接料位1_扫码工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "接料位1" && d.Station == "扫码工位");
                pos_接料位2_扫码工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "接料位2" && d.Station == "扫码工位");
                pos_扫码位1_扫码工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "扫码位1" && d.Station == "扫码工位");
                pos_扫码位2_扫码工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "扫码位2" && d.Station == "扫码工位");
                pos_取料位_扫码工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料位" && d.Station == "扫码工位");
                pos_取料位_下料翻转工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料位" && d.Station == "下料翻转工位");
                pos_真空确认位_下料翻转工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "真空确认位" && d.Station == "下料翻转工位");
                pos_取料接近位_下料翻转工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料接近位" && d.Station == "下料翻转工位");
                pos_放料位_下料翻转工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "放料位" && d.Station == "下料翻转工位");
                pos_取料位_下料搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料位" && d.Station == "下料搬运工位");
                pos_放料位_下料搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "放料位" && d.Station == "下料搬运工位");
                pos_取料高位_下料搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料高位" && d.Station == "下料搬运工位");
                pos_放料高位_下料搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "放料高位" && d.Station == "下料搬运工位");
                pos_安全位_下料搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "安全位" && d.Station == "下料搬运工位");
                pos_转盘初始位_转盘旋转 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "转盘初始位" && d.Station == "转盘旋转");
                pos_接料位_PPG搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "接料位" && d.Station == "PPG搬运工位");
                pos_PPG下方位_PPG搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "PPG下方位" && d.Station == "PPG搬运工位");
                pos_取料位_PPG搬运工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "取料位" && d.Station == "PPG搬运工位");
                pos_安全位_PPG下压工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "安全位" && d.Station == "PPG下压工位");
                pos_过渡位_PPG下压工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "过渡位" && d.Station == "PPG下压工位");
                pos_下压位_PPG下压工位 = MachineDataManager.Instance.PositionList.SingleOrDefault(d => d.PositionName == "下压位" && d.Station == "PPG下压工位");

                #endregion

                #region 光源
                ImageLightInit(Common.CurProType);
                #endregion

                PosArray_扫码工位接料 = new Position[2] { pos_接料位1_扫码工位, pos_接料位2_扫码工位 };
                PosArray_扫码工位扫码 = new Position[2] { pos_扫码位1_扫码工位, pos_扫码位2_扫码工位 };

                VacuumArray_翻转真空吸 = new OutputSetting[2] { do_翻转真空吸1, do_翻转真空吸2 };
                VacuumArray_翻转真空破 = new OutputSetting[2] { do_翻转真空破1, do_翻转真空破2 };

                VacuunArray_转盘真空检测 = new InputSetting[8] { di_转盘真空检测1, di_转盘真空检测2, di_转盘真空检测3, di_转盘真空检测4, di_转盘真空检测5, di_转盘真空检测6, di_转盘真空检测7, di_转盘真空检测8 };
                VacuunArray_转盘真空破 = new OutputSetting[8] { do_转盘真空破1, do_转盘真空破2, do_转盘真空破3, do_转盘真空破4, do_转盘真空破5, do_转盘真空破6, do_转盘真空破7, do_转盘真空破8 };
                VacuunArray_转盘真空吸 = new OutputSetting[8] { do_转盘真空吸1, do_转盘真空吸2, do_转盘真空吸3, do_转盘真空吸4, do_转盘真空吸5, do_转盘真空吸6, do_转盘真空吸7, do_转盘真空吸8 };
                #region 未赋值对象判断
                //List<string> 未成功赋值对象 = new List<string>();
                //Type type = typeof(Machine);
                //var Fields = type.GetFields();
                //foreach (var item in Fields)
                //{
                //    var attr = item.GetCustomAttribute<MachinePropAttr>();
                //    if (attr != null && attr.Line != Common.SP_线体)
                //    {
                //        continue;
                //    }
                //    if (item.FieldType == typeof(InputSetting))
                //    {
                //        InputSetting input = (InputSetting)item.GetValue(null);
                //        if (input == null)
                //        {
                //            未成功赋值对象.Add(item.Name);
                //        }
                //    }
                //    else if (item.FieldType == typeof(OutputSetting))
                //    {
                //        OutputSetting ouput = (OutputSetting)item.GetValue(null);
                //        if (ouput == null)
                //        {
                //            未成功赋值对象.Add(item.Name);
                //        }
                //    }
                //    else if (item.FieldType == typeof(Position))
                //    {
                //        Position position = (Position)item.GetValue(null);
                //        if (position == null)
                //        {
                //            未成功赋值对象.Add(item.Name);
                //        }
                //    }
                //    else if (item.FieldType == typeof(ImageLights))
                //    {
                //        ImageLights imgLights = (ImageLights)item.GetValue(null);
                //        if (imgLights == null)
                //        {
                //            未成功赋值对象.Add(item.Name);
                //        }
                //    }
                //}
                //StringBuilder sb = new StringBuilder();
                //foreach (var item in 未成功赋值对象)
                //{
                //    sb.Append(item);
                //    sb.Append(",");
                //}
                //if (sb.Length > 0)
                //    sb.Remove(sb.Length - 1, 1);
                //if (sb.Length > 0)
                //    Common.AppendUiLog.Log($"未成功赋值：{sb}");
                var Fields = typeof(Machine).GetFields().ToList();
                Fields.RemoveAll(x => x.GetValue(null) != null);
                if (Fields.Count() > 0)
                {
                    string str = "未成功赋值:";
                    Fields.ForEach(x => str += $"{x.Name}.");
                    Common.AppendUiLog.Log(str);
                }
                #endregion
            }
            catch (Exception ex)
            {

            }
        }
    }
}